# $Id$
# Maintainer: Jan de Groot <jgc@archlinux.org>

pkgbase=freetype2
pkgname=('freetype2' 'freetype2-demos' 'freetype2-docs')
pkgver=2.9.1
pkgrel=1
pkgdesc="Font rasterization library"
arch=(x86_64)
license=('GPL')
url="https://www.freetype.org/"
# adding harfbuzz for improved OpenType features auto-hinting
# introduces a cycle dep to harfbuzz depending on freetype wanted by upstream
depends=('zlib' 'bzip2' 'sh' 'libpng' 'harfbuzz')
makedepends=('libx11')
source=(https://download-mirror.savannah.gnu.org/releases/freetype/freetype-${pkgver}.tar.bz2{,.sig}
        https://download-mirror.savannah.gnu.org/releases/freetype/freetype-doc-${pkgver}.tar.bz2{,.sig}
        https://download-mirror.savannah.gnu.org/releases/freetype/ft2demos-${pkgver}.tar.bz2{,.sig}
        0001-Enable-table-validation-modules.patch
        0002-Enable-infinality-subpixel-hinting.patch
        0003-Enable-long-PCF-family-names.patch
        0005-freetype-2.5.2-more-demos.patch
        freetype2.sh)
sha1sums=('220c82062171c513e4017c523d196933c9de4a7d'
          'SKIP'
          'bb6c973f9fef972ad4ecc03bc09ed676b8dc0d59'
          'SKIP'
          '45704d7b75c4f9fdd6a9b3787918e8220b36aa77'
          'SKIP'
          'd9eb22e5c962923089b0c9fc5491cf28a19bd982'
          'd13503902e0404cf3558db76b477f23f9910d06e'
          'fc49742fb6c19fe0677e3552bb7c00aac8530265'
          '72cfecbe738085eec475e012617661ad0cc9b76f'
          'bc6df1661c4c33e20f5ce30c2da8ad3c2083665f')
validpgpkeys=('58E0C111E39F5408C5D3EC76C1A60EACE707FDA5')

prepare() {
  # Rename source dir to allow building the demos
  mv freetype-${pkgver} freetype2
  mv ft2demos-${pkgver} freetype2-demos

  cd freetype2
  patch -Np1 -i ../0001-Enable-table-validation-modules.patch
  patch -Np1 -i ../0002-Enable-infinality-subpixel-hinting.patch
  patch -Np1 -i ../0003-Enable-long-PCF-family-names.patch

  cd ../freetype2-demos
  # enable more demos
  patch -Np1 -i ../0005-freetype-2.5.2-more-demos.patch

  # Suppress RPATH
  sed -i '/X11_LIB:%=-R%/d' graph/x11/rules.mk
}

build() {
  cd freetype2
  ./configure --prefix=/usr --disable-static
  make

  # Build demos
  cd ../freetype2-demos
  make
}

check() {
  cd freetype2
  make -k check
}

package_freetype2() {
  provides=('libfreetype.so')
  install=freetype2.install
  backup=('etc/profile.d/freetype2.sh')

  cd freetype2
  make DESTDIR="${pkgdir}" install
  install -Dt "${pkgdir}/etc/profile.d" -m644 ../freetype2.sh
}

package_freetype2-demos() {
  pkgdesc="Freetype tools and demos"
  depends=('freetype2' 'libx11')

  cd freetype2-demos
  install -d "${pkgdir}/usr/bin"
  for _i in bin/{f,t}t*; do
    libtool --mode=install install $_i "${pkgdir}/usr/bin"
  done
}

package_freetype2-docs() {
  pkgdesc="Freetype documentation"
  depends=('freetype2')

  cd freetype2
  install -d "${pkgdir}/usr/share/doc"
  cp -a docs "${pkgdir}/usr/share/doc/freetype2"
}

# vim:set ts=2 sw=2 et:
